package com.rc.evcharger.common.utils;


public class YlDataUtil {

    /**
     * @param terminalId or orderNum 把桩编号解析为32位16进制的ASCII码的帧
     * @return
     */
    public static String getTerminalIdFrame(String terminalId) {
        //String s = StringUtil.stringToAscii(terminalId);
        String s = NumberUtil.bin2HexStr(terminalId.getBytes());

        String[] split = s.split(DataUtil.SPLIT);

        StringBuffer sb = new StringBuffer();
        sb.append(s).append(DataUtil.SPLIT);

        for (int i = split.length; i < 32; i++) {
            sb.append("00").append(DataUtil.SPLIT);
        }

        return sb.toString().trim();
    }


    public static String dataToASCIIFrame(String cmdData, int length) {
        //String s = StringUtil.stringToAscii(terminalId);
        String s = NumberUtil.bin2HexStr(cmdData.getBytes());

        String[] split = s.split(DataUtil.SPLIT);

        StringBuffer sb = new StringBuffer();
        sb.append(s).append(DataUtil.SPLIT);

        for (int i = split.length; i < length; i++) {
            sb.append("30").append(DataUtil.SPLIT);
        }

        return sb.toString().trim();
    }

    public static void main(String[] args) {
        String terminalIdFrame = YlDataUtil.getTerminalIdFrame("115344000111002007231524200323");
        System.out.println(terminalIdFrame);

        String s = YlDataUtil.dataToASCIIFrame("hlht://115344000021.914401153/", 256);
        System.out.println(s);
        System.out.println(s.split(" ").length);
    }
}
